package com.makinolo.rlvforge.tacx.data
{
	import flash.utils.ByteArray;
	import com.makinolo.rlvforge.tacx.utils.StringUtils;
	

public class GeneralInfo implements Persistent
{
	private static const COURSENAME_LEN:int = 16;
	public static const WATT_PROGRAM:int = 0;
	public static const SLOPE_PROGRAM:int = 1;
	public static const PULSE_PROGRAM:int = 2;
	public static const TIME_PROGRAM:int = 0;
	public static const DISTANCE_PROGRAM:int = 1;
	
	public static const RECORD_SIZE:int = 70;
	
	private var CheckSum:Number;
	private var CourseName:String;	// Always read 34 bytes UNICODE 		
	private var WattSlopePulse:int;	//0 = Watt program, 1 = Slope program, 2 = Pulse (HR) program
	private var TimeDist:int;		//0 = Time based program, 1 = distance based program
	private var TotalTimeDist:Number;	//Total time (in seconds) or distance (in metres) of complete program
	private var EnergyCons:Number;	
	private var AltitudeStart:Number;	
	private var BrakeCategory:int;

	public function GeneralInfo( checkSum:Number, courseName:String, wattSlopePulse:int, 
			timeDist:int, totalTimeDist:Number, energyCons:Number, 
			altitudeStart:Number, brakeCategory:int)
	{
		CheckSum = checkSum;
		setCourseName(courseName);
		WattSlopePulse = wattSlopePulse;
		TimeDist = timeDist;
		TotalTimeDist = totalTimeDist;
		EnergyCons = energyCons;
		AltitudeStart = altitudeStart;
		BrakeCategory = brakeCategory;
	}		
	
/*	public function GeneralInfo(LEDataInputStream dis) throws IOException
	{
		CheckSum = dis.readUnsignedInt();
		CourseName = dis.readString(COURSENAME_LEN); 		
		WattSlopePulse = dis.readInt();
		TimeDist = dis.readInt();
		TotalTimeDist = dis.readDouble();
		EnergyCons = dis.readDouble();	
		AltitudeStart = dis.readFloat();	
		BrakeCategory = dis.readInt();
	}*/
	
	public function getAltitudeStart():Number
	{
		return AltitudeStart;
	}
	public function setAltitudeStart(altitudeStart:Number):void
	{
		AltitudeStart = altitudeStart;
	}
	public function getBrakeCategory():int
	{
		return BrakeCategory;
	}
	public function setBrakeCategory(brakeCategory:int):void
	{
		BrakeCategory = brakeCategory;
	}
	public function getCheckSum():Number
	{
		return CheckSum;
	}
	public function setCheckSum(checkSum:Number):void
	{
		CheckSum = checkSum;
	}
	public function getCourseName():String
	{
		return CourseName;
	}
	public function setCourseName( courseName:String):void
	{
		CourseName = StringUtils.stuff(courseName, 0, COURSENAME_LEN);
	}
	public function getEnergyCons():Number
	{
		return EnergyCons;
	}
	public function setEnergyCons(energyCons:Number):void
	{
		EnergyCons = energyCons;
	}
	public function getTimeDist():int
	{
		return TimeDist;
	}
	public function setTimeDist(timeDist:int):void
	{
		TimeDist = timeDist;
	}
	public function getTotalTimeDist():Number
	{
		return TotalTimeDist;
	}
	public function setTotalTimeDist(totalTimeDist:Number):void
	{
		TotalTimeDist = totalTimeDist;
	}
	public function getWattSlopePulse():int
	{
		return WattSlopePulse;
	}
	public function setWattSlopePulse( wattSlopePulse:int):void
	{
		WattSlopePulse = wattSlopePulse;
	}
	
	public function persist(dos:ByteArray):void
	{
		dos.writeUnsignedInt(CheckSum);
		dos.writeBytes(StringUtils.StringToTacxBytes(CourseName));
		dos.writeInt(WattSlopePulse);
		dos.writeInt(TimeDist);
		dos.writeDouble(TotalTimeDist);
		dos.writeDouble(EnergyCons);	
		dos.writeFloat(AltitudeStart);	
		dos.writeInt(BrakeCategory);
	}
}
}